﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using ZD_DataModel;
using ZD_DataProvider;

namespace ZD_Business
{
    public class ZD_BusinessBase : IBusinessBase
    {
        #region 私有变量定义
        private IDataProvider DataProviderBase = null;
        #endregion

        public ZD_BusinessBase()
        {

        }


        #region 通用CRUD
        #region 查询
        /// <summary>
        /// 返回实体泛型集合
        /// </summary>
        /// <typeparam name="IDataModel"></typeparam>
        /// <returns></returns>
        public List<T> GetList<T>(IDataModel Model) where T : IDataModel, new()
        {
            DataProviderBase = new ZD_DataProviderBase(Model);
            return DataProviderBase.GetList<T>();
        }

        /// <summary>
        /// 分页查询返回实体类泛型集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public List<T> GetPageList<T>(IDataModel Model, ref int DataTotalCount) where T : IDataModel, new()
        {
            DataProviderBase = new ZD_DataProviderBase(Model);
            return DataProviderBase.GetPageList<T>(ref DataTotalCount);
        }

        /// <summary>
        /// 返回DataSet
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public DataSet GetDataSet(IDataModel Model)
        {
            DataProviderBase = new ZD_DataProviderBase(Model);
            return DataProviderBase.GetDataSet();
        }

        /// <summary>
        /// 分页查询返回DataSet
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public DataSet GetPageDataSet(IDataModel Model, ref int DataTotalCount)
        {
            DataProviderBase = new ZD_DataProviderBase(Model);
            return DataProviderBase.GetPageDataSet(ref DataTotalCount);
        }


        /// <summary>
        /// 根据指定条件获取对应Model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Model"></param>
        /// <returns></returns>
        public T GetModel<T>(IDataModel Model) where T : IDataModel, new()
        {
            DataProviderBase = new ZD_DataProviderBase(Model);
            return DataProviderBase.GetModel<T>();
        }
        #endregion

        #region 新增
        /// <summary>
        /// 新增记录
        /// </summary>
        /// <returns>返回新增后的实体</returns>
        public T InsertReturnModel<T>(IDataModel Model) where T : IDataModel, new()
        {
            DataProviderBase = new ZD_DataProviderBase(Model);
            return DataProviderBase.InsertReturnModel<T>();
        }

        /// <summary>
        /// 新增记录
        /// </summary>
        /// <returns>返回被影响行数</returns>
        public int InsertReturnAffectRows(IDataModel Model)
        {
            DataProviderBase = new ZD_DataProviderBase(Model);
            return DataProviderBase.InsertReturnAffectRows(Model);
        }
        #endregion

        #region 删除

        /// <summary>
        ///  根据主键删除对应记录
        /// </summary>
        /// <returns>返回被影响行数</returns>
        public int DeleteReturnAffectRows(IDataModel Model)
        {
            DataProviderBase = new ZD_DataProviderBase(Model);
            return DataProviderBase.DeleteReturnAffectRows();
        }
        #endregion

        #region 修改

        /// <summary>
        ///  根据主键修改对应记录
        /// </summary>
        /// <returns>返回被影响行数</returns>
        public int UpdateReturnAffectRows(IDataModel Model)
        {
            DataProviderBase = new ZD_DataProviderBase(Model);
            return DataProviderBase.UpdateReturnAffectRows();
        }
        #endregion
        #endregion
    }
}
